package com.littlebee.storysuper.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.littlebee.storysuper.R;
import com.littlebee.storysuper.fragment.LoginFragment;
import com.littlebee.storysuper.fragment.RegisterFragment;
import com.zss.library.activity.BaseActivity;
import com.zss.library.indicator.UnderlinePageIndicator;
import com.zss.library.toolbar.CommonToolbar;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述：注册登录界面
 */
public class RegisterActivity extends BaseActivity {
    private ViewPager mViewPager;
    private UnderlinePageIndicator mPageIndicator;
    private List<Fragment> mList = new ArrayList<Fragment>();
    private RadioGroup mRadioGroup;
    private RadioButton rd1, rd2;
    public static boolean isFirst;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_register_view;
    }

    @Override
    public void initView() {
        super.initView();
        isFirst=getIntent().getBooleanExtra("isFirst",false);
        mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        mPageIndicator = (UnderlinePageIndicator) findViewById(R.id.indicator);
        mPageIndicator.setHorizontalScrollBarEnabled(false);
        mViewPager = (ViewPager) findViewById(R.id.activity_content);
        rd1 = (RadioButton) findViewById(R.id.radio1);
        rd2 = (RadioButton) findViewById(R.id.radio3);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        LoginFragment fragment1 = new LoginFragment();
        mList.add(fragment1);

        RegisterFragment fragment3 = new RegisterFragment();
        mList.add(fragment3);
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

            @Override
            public int getCount() {
                return mList.size();
            }

            @Override
            public Fragment getItem(int position) {
                return mList.get(position);
            }

        });
        mPageIndicator.setViewPager(mViewPager);
        mPageIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                mList.get(position).setUserVisibleHint(true);
                if(position == 0){
                    mRadioGroup.check(R.id.radio1);
                }

                else if(position == 1){
                    mRadioGroup.check(R.id.radio3);
                }
                changTextColor(position);
            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(checkedId == R.id.radio1){
                    mViewPager.setCurrentItem(0);
                }
                else if(checkedId == R.id.radio3){
                    mViewPager.setCurrentItem(1);
                }
            }
        });
    }

    @Override
    public void setTopBar() {
        setStatusBarColor(R.color.module_video_bg);
        CommonToolbar toolbar = getToolbar();
        toolbar.setBgRes(R.color.module_video_bg);
        toolbar.setTitle(getString(R.string.login_txt));

    }
    private void changTextColor(int index) {
        rd1.setTextColor(getResources().getColor(R.color.colorGrey));
        rd2.setTextColor(getResources().getColor(R.color.colorGrey));
        if(index==0){
            rd1.setTextColor(getResources().getColor(R.color.module_video_bg));

        }else{
            rd2.setTextColor(getResources().getColor(R.color.module_video_bg));

        }
    }
}
